class PublicInterface {
  constructor(props) {
  }

  //查询table字段列表
  pubtabcolsList = (entryProps,params,callback) => {
    const { dispatch } = entryProps;
    dispatch({
      type: 'layerSetting/pubtabcolsList',
      payload: params,
    }).then(response => {
      if (response) {
        callback(this.formateArrDataA(response,'tableId'));
      }
    });
  };

  //查询服务列表
  pubServiceList = (entryProps,callback) => {
    const { dispatch } = entryProps;
    dispatch({
      type: 'space/spaceResourcesQuery',
      payload: {},
    }).then(response => {
      if (response) {
        callback(response);
      }
    });
  };

  //查询配置列表
  mapConfigList = (entryProps,value,callback) => {
    const { dispatch } = entryProps;
    dispatch({
      type: 'layerSetting/mapConfigList',
      payload: {mapName:value},
    }).then(response => {
      if (response) {
        callback(response);
      }
    });
  };

  formateArrDataA = (initialArr, name) => {
    // 判定传参是否符合规则
    if (!(initialArr instanceof Array)) {
      console.log('请传入正确格式的数组');
      return;
    }
    if (!name) {
      console.log('请传入对象属性');
      return;
    }
    //先获取一下这个数组中有多少个"name"
    let nameArr = []
    for (let i in initialArr) {
      if (nameArr.indexOf(initialArr[i][`${name}`]) === -1) {
        nameArr.push(initialArr[i][`${name}`])
      }
    }
    //新建一个包含多个list的结果对象
    let tempObj = {}
    // 根据不同的"name"生成多个数组
    for (let k in nameArr) {
      for (let j in initialArr) {
        if (initialArr[j][`${name}`] == nameArr[k]) {
          // 每次外循环时新建一个对应"name"的数组, 内循环时当前数组不变
          tempObj[nameArr[k]] = tempObj[nameArr[k]] || []
          tempObj[nameArr[k]].push(initialArr[j])
        }
      }
    }
    return tempObj
  }
}

export default PublicInterface;
